﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Serializer s = new Serializer();
            s.DeSerializeObject(CompanyManager.passwordPath);

            IntPtr unmanagedString = IntPtr.Zero;
            unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureTextBox1.SecureText);
            string pass = Marshal.PtrToStringUni(unmanagedString);
            Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);

            if ((textBox1.Text.CompareTo(CompanyManager.lso.UserName) == 0) &&
                (pass.CompareTo(CompanyManager.lso.PassWord) == 0))
            {
                CompanyManager.enter = true;
                this.Close();
            }
            else 
            {
                MessageBox.Show("יש להזין פרטים נכונים", "פרטים שגויים",
                MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
                MessageBoxDefaultButton.Button1); 
            }
        }
    }
}
